package cn.cc.compare;


import java.util.ArrayList;
import java.util.Arrays;

class Student implements java.lang.Comparable<Student>{
    private String name ;
    private int score ;
    private int age ;
    public Student(String name,int age , int score){
        this.name = name ;
        this.age = age ;
        this.score = score ;
    }
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", score=" + score +
                ", age=" + age +
                '}';
    }

    @Override
    public int compareTo(Student o) {
        if (this.score < o.score) {
            return -1 ;
        }
        if (this.score > o.score) {
            return 1 ;
        }else{
            if (this.age < o.age) {
                return -1 ;
            }
            if (this.age > o.age) {
                return 1 ;
            }else{
                return 0 ;
            }
        }
    }
}
public class Comparable {
    public static void main(String[] args) {
        Student stu[] = {new Student("chenchao", 23, 100), new Student("wangjian", 24, 99), new Student("xuanye", 22, 87)};
        Arrays.sort(stu);
        for (Student x:stu
             ) {
            System.err.println(x);
        }
    }
}
